package com.ingesup.services;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import com.ingesup.entities.Contact;
import com.ingesup.entities.LettreType;
import com.ingesup.entities.ListeDeDiffusion;
import com.ingesup.email.*;

public class EmailServiceImpl implements EmailService {

	@Override
	public boolean envoyerEmail(ListeDeDiffusion liste, LettreType lettre) {
		for (Contact ct : liste.getListeDeContacts()) {
			try {
				EmailSender.sendEmailSSL(lettre, ct);
			} catch (AddressException e) {
				e.printStackTrace();
				return false;
			} catch (MessagingException e) {
				e.printStackTrace();
				return false;
			}
		}
		return true;
	}

	@Override
	public boolean envoyerEmail(Contact contact, LettreType lettre) {
		try {
			return EmailSender.sendEmailSSL(lettre, contact);
		} catch (AddressException e) {
			e.printStackTrace();
			return false;
		} catch (MessagingException e) {
			e.printStackTrace();
			return false;
		}
	}

}
